package holdem.pokergui;

import holdem.Card;
import java.awt.*;
import javax.swing.*;

public class MyCard extends JLabel
{
    public static final int WIDTH = 100;
    public static final int HEIGHT = 100;
    private ImageIcon bg;
    private final Integer suit, value;
    private static String[] SUIT = {"spade", "heart", "diamond", "club"};

    MyCard(Card card)
    {
        suit = card.getSuiteInt();
        value = card.getValue();
        setFile(picSource());
    }

    public void setFile(String str)
    {
        bg = new ImageIcon(str);
        setPreferredSize(new Dimension(WIDTH, HEIGHT));
        repaint();
    }

    @Override
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        if(bg != null)
            g.drawImage(bg.getImage(), 0, 0, WIDTH, HEIGHT, this);
    }

    @Override
    public String toString() {
        return Integer.toString(suit) + Integer.toString(value);
    }

    public ImageIcon img()
    {
        return new ImageIcon(picSource());
    }

    public String picSource() {
        String ret = "200px-Playing_card_" + SUIT[suit] + "_";
	switch (value)
        {
            case 1: ret += "A"; break;
            case 11: ret += "J"; break;
            case 12: ret += "Q"; break;
            case 13: ret += "K"; break;
            default: ret += value;
	}
        ret += ".svg.png";
	return ret;
    }
}